import os
import tensorflow as tf

if __name__ == '__main__':
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    # y1 = x * w1  + b1
    # 求 y1 对 w1 的导数值
    # x = tf.constant(1.)

    x = tf.Variable(initial_value=1.0)
    w1 = tf.constant(2.)
    b1 = tf.constant(3.)

    with tf.GradientTape() as tape:
        # 确认一下 x w1 b1 是常量还是变量
        y1 = x * w1 + b1

    gradient = tape.gradient(y1, x)
    print(gradient)
